home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / euphor14.zip / BITMAP.EX < prev    next >
Text File  |  1996-03-31  |  2KB  |  81 lines

  1. -- bitmap displayer
  2. -- usage: ex bitmap file[.bmp]
  3. --
  4. -- example 16-color bitmap:  ex bitmap c:\windows\leaves
  5. -- ... or 256-color bitmap:  ex bitmap c:\windows\256color
  6.  
  7. -- It tries to use mode 257 for 256-color bitmaps and
  8. -- mode 18 for 16-color or less. If you can't get into mode 257
  9. -- try mode 19, or see graphics.e
  10.  
  11. without type_check
  12. include image.e
  13.  
  14. constant ERR = 2
  15.  
  16. sequence cl
  17. object bitmap
  18. integer xlen, ylen
  19. sequence image, Palette, vc
  20.  
  21. cl = command_line()
  22. if length(cl) < 3 then
  23.     puts(ERR, "usage: ex bitmap file.bmp\n")
  24.     abort(1)
  25. end if
  26. if not find('.', cl[3]) then
  27.     cl[3] = cl[3] & ".bmp"
  28. end if
  29.  
  30. bitmap = read_bitmap(cl[3])
  31.  
  32. if atom(bitmap) then
  33.     -- failure
  34.     if bitmap = BMP_OPEN_FAILED then
  35.     puts(ERR, cl[3] & ": " & "couldn't open\n")
  36.     elsif bitmap = BMP_UNEXPECTED_EOF then
  37.     puts(ERR, cl[3] & ": " & "unexpected end of file\n")
  38.     else
  39.     puts(ERR, cl[3] & ": " & "unsupported format\n")
  40.     end if
  41.     abort(1)
  42. end if
  43.  
  44. Palette = bitmap[1]
  45. image = bitmap[2]
  46.  
  47. integer mode, xstart
  48.  
  49. if length(Palette) > 16 then
  50.     mode = 257  -- do you have this mode?
  51. else
  52.     mode = 18   -- almost everyone has this one
  53. end if
  54. if graphics_mode(mode) then
  55.     puts(ERR, "bad graphics mode\n")
  56.     abort(1)
  57. end if
  58.  
  59. all_palette(Palette/4)  -- set the whole palette
  60.  
  61. display_image({0,0}, image) -- always display first one
  62.  
  63. vc = video_config()
  64.  
  65. -- display others if there's room:
  66. xlen = length(image[1])
  67. ylen = length(image)
  68. xstart = xlen+1
  69. for y = 0 to vc[VC_YPIXELS]-floor(ylen/2) by ylen+1 do
  70.     for x = xstart to vc[VC_XPIXELS]-floor(xlen/2) by xlen+1 do
  71.     display_image({x,y}, image)
  72.     end for
  73.     xstart = 0
  74. end for
  75.  
  76. while get_key() = -1 do
  77. end while
  78. if graphics_mode(-1) then
  79. end if
  80.  
  81.